<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="javax.swing.*" %>

<%--
  Created by IntelliJ IDEA.
  User: 113
  Date: 2020/12/2
  Time: 17:47
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%String path=request.getContextPath();%>>

<html>
<head>

        <title>主页</title>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.css">

        <script src="${pageContext.request.contextPath}/js/jquery.min.js"></script>
        <script src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
        <script src="${pageContext.request.contextPath}/js/bootstrap.bundle.js"></script>

        <style>
            .container{
                width: 50%;
                height: 20%;
                margin-top: 10%;
            }
        </style>
    <style type="text/css">
        a:link {
            color:#000000;
            text-decoration: none;
        }
        a:visited {
            color:#000000;
            text-decoration: none;
        }
        a:hover
        {
            color:#ffffff;
            text-decoration: none;
        }
        a:active {
            color: #ffffff;
            text-decoration: none;
        }
    </style>

    <meta http-equive="content-type" content="text/html;charset=utf-8"/>
    <script type="text/javascript" src="<%=path%>/js/jquery-1.8.3.min.js"></script>
    <style>
        .div1{
            margin-top:28px;
            margin-left:12px;
            float:left;
            font-family:'黑体';
            font-size:20px;
            color:#CCC;
        }
        .div2{
            margin-top:28px;
            margin-right:12px;
            float:right;
            font-family:'黑体';
            font-size:20px;
            color:#CCC;
        }
    </style>
    <script type="text/javascript">
        function logout(){
            $.post("<%=path%>/logout.do");
            alert("注销成功");
            //跳转到父窗口的login.jsp
            window.parent.location.href="<%=path%>/login.jsp";
        }
    </script>
</head>

<body style="background-color:#4e555b;">
<%


    //表示尚未登陆
    if(session.getAttribute("username")==null){
        out.print("尚未登陆，将3s之后跳转页面..");
        response.setHeader("refresh","3;url=login.jsp");
    }else {
        out.print(" ");


        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");

        //建立数据库连接
        String url = "jdbc:mysql://localhost:3306/book";//数据库连接地址
        Connection connection = DriverManager.getConnection(url, "root", "root");

        String sql = "select * from gwy";
        PreparedStatement ps = connection.prepareStatement(sql);

        ResultSet rs = ps.executeQuery();

%>
<div class="div1">公务员信息管理系统</div>
<div class="div2">
    您好:${sessionScope.user.username}
    <a href="#" onclick="logout()">注销</a>
</div>


<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <h3 style="text-align:center">职工信息</h3>
            <a id="modal-addUser" href="#modal-container-addUser" role="button"  class="btn" data-toggle="modal" > 添加新入职职工信息</a>
            <table class="table table-striped">
                <thead>
                <th >编号</th>
                <th >姓名</th>
                <th >年龄</th>
                <th >性别</th>
                <th >入职日期</th>
                <th >工资</th>
                <th >职务</th>
                <th >家庭住址</th>
                <th >联系电话</th>
                <th></th>
                <th style="text-align: center">操作</th>
                </thead>
                <tbody>



                <%
                        while(rs.next()){
                            out.print("<tr>");
                            out.print(
                                    "<td>"+rs.getInt("id")
                                            +"</td><td>"+rs.getString("name")
                                            +"</td><td>"+rs.getInt("age")
                                            +"</td><td>"+rs.getString("sex")
                                            +"</td><td>"+rs.getString("入职日期")
                                            +"</td><td>"+rs.getString("工资")
                                            +"</td><td>"+rs.getString("职务")
                                            +"</td><td>"+rs.getString("家庭住址")
                                            +"</td><td>"+rs.getString("联系电话")
                                            +"<td>"
                                            +"<td><a href='delete.jsp?id="+rs.getString("id")+"'>删除职员信息</a>"
                                            +"&nbsp;<a href='edit.jsp? id="+rs.getString("id")+"'>修改职员信息</a>"+
                                            "</td>"
                            );
                            out.print("</tr>");
                        }
                    }

                %>
                </tbody>
            </table>
        </div>
    </div>
</div>
<div class="modal fade" id="modal-container-addUser" role="dialog" aria-hidden="true" aria-labelledby="myModalLabel" aria-hidden="true">

</div>
</body>
</html>

